package com.easyspringboot.utils;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author xiaoyi
 * @Version 1.0
 * @ClassName PropertiesUtils
 * @Time 2:15
 */
public class PropertiesUtils {
    private static Properties properties = new Properties();
    private static Map<String,String> PROPER_MAP = new ConcurrentHashMap();


    static{
        InputStream is = null;
        try {
            is = PropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
            properties.load(new InputStreamReader(is,"UTF-8"));
            Iterator<Object> iterable =properties.keySet().iterator();
            while (iterable.hasNext()){
                String key = (String) iterable.next();
                PROPER_MAP.put(key,properties.getProperty(key));
            }
            }catch (Exception e){

                }finally {
            try {
                is.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }



    }
    public static String getProperties(String key){
        return PROPER_MAP.get(key);
    }

    public static void main(String[] args) {
        System.out.println(getProperties("db.url"));
    }
}
